<template>
  <div>
    <div class="search-res">
      <a-list @clickItem="clickItem" :list="list" :loading="loading" :finished="finished"> </a-list>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      keyword: "",
      list: [],
      loading: true,
      finished: false,
    };
  },
  mounted() {
    this.keyword = this.$route.query.keyword;
    this.onSearch(this.keyword);
  },
  methods: {
    onSearch(keyword) {
      this.loading = true;
      this.getData(keyword).then((res) => {
        this.list = res;
        this.loading = false;
        this.finished = true;
      });
    },
    getData(keyword) {
      return new Promise(async (resolve, reject) => {
        var list = [];
        let data = await this.$cloud.callFunction({
          name: "article",
          data: {
            action: 'get',
            article: {}
          }
        })
        let result = data.result.data
        for (let i in result) {
          if (result[i].title.indexOf(keyword) > -1) {
            list.push(result[i])
          }
        }
        resolve(list);
      });
    },
    load() {
      // console.log("load");
    },
    clickItem(id) {
      console.log(id)
      this.$router.push("/code/?keyword=" + id);
    }
  },
};

</script>
<style>
</style>
